package com.asia5b.a5mall.middleware.logic.viewmodel.goods

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.goods.Goods2SkuModel
import io.reactivex.functions.Consumer

/**
 * Created by zhangyuncai on 2020/1/11.
 */
class GoodsSpecDFVM : SimpleViewModel() {

    val getGoodsSkuLiveData = MutableLiveData<ArrayList<Goods2SkuModel>>()

    /**
     * 获取sku
     */
    fun getGoodsSku(goodsId: Int) {
        baseSubscribe(goodsApi.getGoodsSku(goodsId), Consumer {
//            providerView().getGoodsSkuResult(it!!)
            getGoodsSkuLiveData.value=it
        })
    }

    val addCartLiveData = MutableLiveData<Boolean>()
    fun addCart(sku_id: Int, num: Int, actId: Int?) {
        baseSubscribe(cartApi.add(sku_id, num, actId), Consumer { data ->
//            providerView().addCartResult()
            addCartLiveData.value=true
        })
    }

    val buyNumLiveData = MutableLiveData<Boolean>()
    fun buyNum(sku_id: Int, num: Int, actId: Int? = null) {
        baseSubscribe(cartApi.buy(sku_id, num, actId), Consumer { data ->
//            providerView().buyNumResult()
            buyNumLiveData.value=true
        })
    }
}